package com.xhs.zdl.demo.wheelCamera;

import android.graphics.Bitmap;
import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;

import com.cjt2325.cameralibrary.JCameraView;
import com.cjt2325.cameralibrary.lisenter.ErrorLisenter;
import com.cjt2325.cameralibrary.lisenter.JCameraLisenter;
import com.xhs.zdl.demo.MyUtils;
import com.xhs.zdl.demo.R;

import java.io.File;

public class WheelCameraActivity extends AppCompatActivity {

    private JCameraView jCameraView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_wheel_camera);

        init();
    }

    private void init() {
        //1.1.1
        jCameraView = (JCameraView) findViewById(R.id.jcameraview);

//设置视频保存路径
        jCameraView.setSaveVideoPath(Environment.getExternalStorageDirectory()
                + File.separator + "XHSiot/video/");

//设置只能录像或只能拍照或两种都可以（默认两种都可以）
        jCameraView.setFeatures(JCameraView.BUTTON_STATE_BOTH);

//设置视频质量
        jCameraView.setMediaQuality(JCameraView.MEDIA_QUALITY_MIDDLE);

//JCameraView监听
        jCameraView.setErrorLisenter(new ErrorLisenter() {
            @Override
            public void onError() {
                //打开Camera失败回调
                MyUtils.Log("open camera error");
            }
            @Override
            public void AudioPermissionError() {
                //没有录取权限回调
                MyUtils.Log("AudioPermissionError");
            }
        });

        jCameraView.setJCameraLisenter(new JCameraLisenter() {
            @Override
            public void captureSuccess(Bitmap bitmap) {
                //获取图片bitmap
                MyUtils.Log("bitmap = " + bitmap.getWidth());
            }
            @Override
            public void recordSuccess(String url,Bitmap firstFrame) {
                //获取视频路径
                MyUtils.Log("url = " + url);
            }

            @Override
            public void quit() {

            }
            //@Override
            //public void quit() {
            //    (1.1.9+后用左边按钮的点击事件替换)
            //}
        });
////左边按钮点击事件
//        jCameraView.setLeftClickListener(new ClickListener() {
//            @Override
//            public void onClick() {
//                WheelCameraActivity.this.finish();
//            }
//        });
////右边按钮点击事件
//        jCameraView.setRightClickListener(new ClickListener() {
//    @Override
//            Toast.makeText(CameraActivity.this,"Right",Toast.LENGTH_SHORT).show();
//        });
    }

    @Override
    protected void onResume() {
        super.onResume();
        jCameraView.onResume();
    }
    @Override
    protected void onPause() {
        super.onPause();
        jCameraView.onPause();
    }
}
